package io.gatling.extensions.redis.builder

import com.typesafe.scalalogging.StrictLogging
import io.gatling.core.action.Action
import io.gatling.core.action.builder.ActionBuilder
import io.gatling.core.check.Check
import io.gatling.core.session.Expression
import io.gatling.core.structure.ScenarioContext
import io.gatling.extensions.redis.action.RedisGetAction
import io.gatling.extensions.redis.protocol.RedisProtocol

class RedisActionBuilder(key: Expression[String]) extends ActionBuilder with StrictLogging {

  private var checks: List[Check[String]] = List.empty[Check[String]]

  def check(checks: Check[String]*): RedisActionBuilder = {
    this.checks = this.checks ::: checks.toList
    this
  }

  override def build(ctx: ScenarioContext, next: Action): Action = {

    import ctx._
    new RedisGetAction(
      key,
      coreComponents,
      protocolComponentsRegistry.components(RedisProtocol.redisProtocolKey),
      throttled,
      checks,
      next
    )
  }
}
